package cn.ynrcb.personnelfile.sysadmin.dao;

import cn.ynrcb.personnelfile.sysadmin.entity.SysDictEntity;
import cn.ynrcb.personnelfile.sysadmin.vo.AddressDictVo;
import cn.ynrcb.personnelfile.sysadmin.vo.DictVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 数据字典表
 *
 * @author wujianfan
 * @email fanxipo@qq.com
 * @date 2021-11-04 16:47:31
 */
@Mapper
public interface SysDictDao extends BaseMapper<SysDictEntity> {

    List<DictVo> selectVoList(@Param(value = "map") Map<String, Object> params);

    List<DictVo> selectRoleVoList();

    @Select("SELECT id,`name` AS label,`level`,pid FROM tb_region WHERE pid = #{pId} AND `status` = 1 ")
    List<AddressDictVo> getAddressDataListByPid(String pId);

    @Select("SELECT id,`name` AS label,`level`,pid FROM tb_region WHERE id = #{pId} AND `status` = 1 ")
    List<AddressDictVo> getAddressDataListById(String id);

    @Select("SELECT id,`name` AS label,`level`,pid FROM tb_region WHERE `level` = 2 AND `status` = 1 ")
    List<AddressDictVo> getZsAddressDataList();

    @Select("SELECT id,`name` AS label,`level`,pid FROM tb_region WHERE `level` = 3 AND pid = #{id} AND `status` = 1 ")
    List<AddressDictVo> getXqAddressDataListByPid(String id);

    @Select("SELECT id,`name` AS label,`level`,pid FROM tb_region WHERE `level` = 3 AND `status` = 1 ")
    List<AddressDictVo> getXqAddressDataList();

    @Select("SELECT id FROM tb_region WHERE `level` = 2 AND SUBSTR(id,1,4) = SUBSTR(#{xqId},1,4) AND `status` = 1  ")
    String getZsIdByXqId(String xqId);

    @Select("SELECT * FROM tb_region WHERE id = #{xqId} AND `status` = 1  ")
    AddressDictVo getAddressById(String xqId);

    /**
     * 通过地区名称来模糊查询昆明市内的县区行政区划代码
     *
     * @param name
     * @return
     */
    @Select("SELECT * FROM tb_region WHERE `name` LIKE CONCAT('%',#{name},'%') AND pid = '530100' AND `status` = 1  ")
    AddressDictVo likeIdByName(String name);

    @Select("SELECT * FROM tb_region WHERE `status` = 1")
    List<AddressDictVo> getAddressList();

    @Select("SELECT id,label,`value` FROM `sys_dict` WHERE type = 'platform' AND `status` = 1")
    List<SysDictEntity> getPlatform();

    @Select("SELECT id,label,`value` FROM `sys_dict` WHERE type = 'field' AND module = 'archor_info' AND `status` = 1")
    List<SysDictEntity> getField();

    @Select("SELECT `label` FROM sys_dict WHERE module = 'archor_info' AND type = 'field' AND `value` = #{field} AND `status` = 1")
    String getFieldByValue(Integer field);

    @Select("SELECT `label` FROM sys_dict WHERE module = 'archor_info' AND type = 'field' AND `value` = #{subField} AND `status` = 1")
    String getSubFieldByValue(Integer subField);
}
